import { createStore } from "vuex";
import { getAccessToken, setAccessToken } from "@/lib/accessToken";
import { login_res } from "@/types/restypes";
//const keepLiveRoute = ["daily", "safe", "todo", "week", "work"];

// let state:login_res= {
//   keepLiveRoute: true,
//   //是否缓存页面
//   userInfo:login_res,
//   //用户信息
//   path: '',
//   //记录上一路径
//   accessToken: getAccessToken(),
//   //获取token

// },
export default createStore({
  state: {
    keepLiveRoute: true,
    //是否缓存页面
    userInfo: { F_SecurityLevel: 1 },
    //用户信息
    path: "",
    //记录上一路径
    accessToken: getAccessToken(),
    //获取token
  },
  getters: {
    accessToken: (state) => state.accessToken,
    userid: (state) => state.userInfo,
    //   view:(state)=>({
    //     navbar_home:true,
    //     navbar_profit:state.userInfo.F_SecurityLevel==18,
    //     navbar_user:true,
    //     top_login:state.userInfo.F_Account,
    //     authentication_natural:!$state.userInfo.F_CheckOnLine,
    //     authentication_shop:$store.state.userInfo.F_CheckOnLine!=2,
    //     user_index_username:$store.state.userInfo.F_Account,
    //     user_index_qrcode:$store.state.userInfo&&$store.state.userInfo.F_CheckOnLine == 2,
    //     user_index_apply:$store.state.userInfo&&$store.state.userInfo.F_CheckOnLine != 2,
    //     user_index_applyShop:$store.state.userInfo.F_SecurityLevel != 18,
    //     user_index_ApplyTips:$store.state.userInfo.F_Account,
    //     user_index_ModuleList:$store.state.userInfo.F_Account,
    // })
  },
  mutations: {
    /**
     * @description 设置accessToken
     * @param {*} state
     * @param {*} accessToken
     */
    setAccessToken(state: any, accessToken: any) {
      // console.log("aaaewdwada", state, accessToken);

      state.accessToken = accessToken.accessToken;
      setAccessToken(accessToken.accessToken);
    },
    /**
     * @description 存储用户信息
     * @param {*} state
     * @param {*} payload
     */
    GetuserInfo(state: any, payload: any) {
      // console.log("```", state, "```````````````", payload);

      state.userInfo = payload.userInfo;
      try {
        sessionStorage.userInfo = JSON.stringify(payload.userInfo);
      } catch (e) {
        console.log(e);
      }
    },
    /**
     * @description 存储路由地址
     * @param {*} state
     * @param {*} payload
     */
    Retainpath(state: any, payload: any) {
      state.path = payload.path;
    },
    ClearKeep(state) {
      if (state.keepLiveRoute) state.keepLiveRoute = false;
      console.log("清空缓存路由！");
    },
    SetKeep(state) {
      if (!state.keepLiveRoute) state.keepLiveRoute = true;
      console.log("设置缓存路由！");
    },
  },
  actions: {},
  modules: {},
});
